<template>
	<tl-sub-page :render="render" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog tap-edit-dialog" width="1100px" top="50px" @open="open" @close="close">
		<el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px">
			<div class="form-content">
				<div>
					<div class="square"></div>
					问题告警信息
				</div>
				<div>&nbsp;</div>
				<div>
					<el-tag>请点击告警单左下角【查看流程文档】，查看《MQ-ES-16.7.5_CL8 质量改进流程评审要素》，质量改进相关任务活动要符合此文件要求。</el-tag>
				</div>
				<div>&nbsp;</div>
				<div>
					<el-tag type="danger" style="color:red" v-if="model.enabled === 0">&nbsp;&nbsp;<i class="el-icon-warning"></i>&nbsp;{{ model.cancelreason }}</el-tag>
				</div>
				<div>&nbsp;</div>
				<el-row>
					<el-col :span="8">
						<el-form-item label="问题分级" prop="problemgrading" :rules="rules.validateRequire">
							<el-select v-model="model.problemgrading" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.problemgradingList" :key="item.code" :label="item.name" :value="item.code" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="问题编号" prop="docno">
							<el-input v-model="model.docno" :disabled="true" placeholder="由系统自动生成"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="单据日期" prop="docdate" :rules="rules.validateRequire">
							<el-date-picker v-model="model.docdate" type="date" :disabled="disableEditSubmit || ApprovalDisable" placeholder="时间" value-format="yyyy-MM-dd" :picker-options="expireTimeOPtion"></el-date-picker>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="申请人" prop="usercode" :rules="rules.validateRequire">
							<!-- <tl-ref-user v-model="model.usercode" :disabled="disableEditSubmit || ApprovalDisable" :initDisplayData.sync="model.username" dataType="code" :singleSelect="true"></tl-ref-user> -->
							<tl-ref-user v-model="model.usercode" :disabled="true" :initDisplayData.sync="model.username" dataType="code" :singleSelect="true"></tl-ref-user>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="8">
						<el-form-item label="创建日期" prop="submitdate">
							<el-date-picker v-model="model.submitdate" :disabled="disableEditSubmit || ApprovalDisable" type="date" placeholder="提交时间" value-format="yyyy-MM-dd"></el-date-picker>
						</el-form-item>
					</el-col> -->
					<el-col :span="8">
						<el-form-item label="状态" prop="state">
							<el-select v-model="model.state" filterable clearable placeholder="审批状态" :disabled="true">
								<el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item label="产品名称" prop="productname" :rules="rules.validateRequire">
							<el-input v-model="model.productname" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.productname = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="硬件版本" prop="hardwareversion">
							<el-input v-model="model.hardwareversion" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.hardwareversion = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="软件版本" prop="softwareversion">
							<el-input v-model="model.softwareversion" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.softwareversion = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="MES条码" prop="mesbarcode">
							<el-input v-model="model.mesbarcode" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.mesbarcode = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="问题来源单号" prop="sourcedocno">
							<el-input v-model="model.sourcedocno" :disabled="disableEditSubmit || ApprovalDisable" placeholder="生产订单号或试验委托单号" @blur="model.sourcedocno = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="问题发生环节" prop="happennode" :rules="rules.validateRequire">
							<!-- <el-select v-model="model.happennode" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.happennodeList" :key="item.code" :label="item.name" :value="item.code" />
							</el-select> -->
							<ref-datacode-select :value="model.happennode" :dataplace="parseInt(2)" :disabled="disableEditSubmit || ApprovalDisable" datacode="QemProblemHappennode" @inputvalue="inputHappennode"></ref-datacode-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="工序/实验类别" prop="classes" :rules="rules.validateRequire">
							<el-input v-model="model.classes" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.classes = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item label="问题来源描述" prop="sourcedesc">
							<el-input v-model="model.sourcedesc" placeholder="请输入关于问题来源的简短描述" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.sourcedesc = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="信息途径" prop="pathway" :rules="rules.validateRequire">
							<el-select v-model="model.pathway" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.pathwayList" :key="item.code" :label="item.name" :value="item.code" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="发生地" prop="occurred" :rules="rules.validateRequire">
							<el-input v-model="model.occurred" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.occurred = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="问题反馈人" prop="feedbackpersoncode" :rules="rules.validateRequire">
							<tl-ref-user v-model="model.feedbackpersoncode" :disabled="disableEditSubmit || ApprovalDisable" :initDisplayData.sync="model.feedbackperson" dataType="code" :singleSelect="true"></tl-ref-user>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="8">
						<el-form-item label="IPD节点" prop="ipdnode" :rules="rules.validateRequire">
							<el-select v-model="model.ipdnode" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.ipdnodeList" :key="item.code" :label="item.name" :value="item.code" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="需求包" prop="requirements" :rules="rules.validateRequire" required>
							<!-- <el-select v-model="model.requirements" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.requirementsList" :key="item.code" :label="item.name" :value="item.code" />
							</el-select> -->
							<ref-datacode-select :value="model.requirements" :dataplace="parseInt(0)" :disabled="disableEditSubmit || ApprovalDisable" datacode="QemProblemRequirements" @inputvalue="inputRequirements"></ref-datacode-select>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="8">
						<el-form-item label="信息途径" prop="pathway" :rules="rules.validateRequire">
							<el-select v-model="model.pathway" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.pathwayList" :key="item.code" :label="item.name" :value="item.code" />
							</el-select>
						</el-form-item>
					</el-col> -->
					<!-- <el-col :span="8">
						<el-form-item label="是否重复发生" prop="repeat" :rules="rules.validateRequire">
							<el-select v-model="model.repeat" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.repeatList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
							</el-select>
						</el-form-item>
					</el-col> -->
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item label="告警主题" prop="warningtitle" :rules="rules.validateRequire">
							<el-input v-model="model.warningtitle" placeholder="概述问题，填写的内容会包含在告警邮件主题中" :disabled="disableEditSubmit || ApprovalDisable" :maxlength="maxLengthFormItem('warningtitle')" @blur="model.warningtitle = $event.target.value.trim()"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item label="问题描述" prop="problemdesc" :rules="rules.validateRequire">
							<el-input v-model="model.problemdesc" placeholder="简述异常问题的现象、影响后果等" :disabled="disableEditSubmit || ApprovalDisable" :maxlength="maxLengthFormItem('problemdesc')" :show-word-limit="true" @blur="model.problemdesc = $event.target.value.trim()" type="textarea" rows="3"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item label="不良情况" prop="rejects" :rules="rules.validateRequire">
							<el-input v-model="model.rejects" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.rejects = $event.target.value.trim()" placeholder="描述问题产生的不良情况，如不良率、不良品数量" type="textarea" rows="1"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item label="紧急处理方式" prop="emergenttreatment" :rules="rules.validateRequire">
							<el-input v-model="model.emergenttreatment" :disabled="disableEditSubmit || ApprovalDisable" @blur="model.emergenttreatment = $event.target.value.trim()" placeholder="描述问题的紧急临时处理方案，如封库返工、现场升级、需产品线评估等" type="textarea" rows="1"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="复核人姓名" prop="reviewman" :rules="requireFormItem('reviewman')">
							<tl-ref-user v-model="model.reviewmancode" :disabled="disabledFormItemWithPermission('reviewman')" :initDisplayData.sync="model.reviewman" dataType="code" :singleSelect="true"></tl-ref-user>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="项目经理" prop="projectmanagercode">
							<tl-ref-user v-model="model.projectmanagercode" :disabled="disableEditSubmit || ApprovalDisable" :initDisplayData.sync="model.projectmanager" dataType="code" :singleSelect="true"></tl-ref-user>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="是否重复发生" prop="repeat" :rules="rules.validateRequire">
							<el-select v-model="model.repeat" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.repeatList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="违反质量政策条款" prop="whetherqualitypolicy" :rules="rules.validateRequire">
							<el-select v-model="model.whetherqualitypolicy" filterable clearable :disabled="disableEditSubmit || ApprovalDisable">
								<el-option v-for="item in codeModel.repeatList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row v-if="model.whetherqualitypolicy === 1">
					<el-col :span="24">
						<el-form-item label="违反条款内容" prop="violationcontent" :rules="rules.validateRequire">
							<el-input v-model="model.violationcontent" :disabled="disableEditSubmit || ApprovalDisable" type="textarea" :rows="4" maxlength="2000" :show-word-limit="true"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="问题归属产品线" prop="productlinename" :rules="requireFormItem('productlinename')">
							<el-input v-model="model.productlinename" :disabled="true" class="tl-ref-selector">
								<el-button slot="append" type="primary" icon="el-icon-search" :disabled="disabledFormItemWithPermission('productlinename')" @click="openqemDutyDeptRefDialog('productline')"></el-button>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="风险排查负责人" prop="riskman" :rules="requireFormItem('riskman')">
							<tl-ref-user v-model="model.riskmancode" :disabled="disabledFormItemWithPermission('riskman')" :initDisplayData.sync="model.riskman" dataType="code" :singleSelect="true"></tl-ref-user>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="牵头分析部门" prop="dutydeptname" :rules="requireFormItem('dutydeptname')">
							<el-input v-model="model.dutydeptname" :disabled="true" class="tl-ref-selector">
								<el-button slot="append" type="primary" icon="el-icon-search" :disabled="disabledFormItemWithPermission('dutydeptname')" @click="openqemDutyDeptRefDialog('dutydept')"></el-button>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="问题分析负责人" prop="assayer" :rules="requireFormItem('assayer')">
							<tl-ref-user v-model="model.assayercode" :disabled="disabledFormItemWithPermission('assayer')" :initDisplayData.sync="model.assayer" dataType="code" :singleSelect="true"></tl-ref-user>
						</el-form-item>
					</el-col>
				</el-row>
			</div>
			<div class="form-content">
				<div>
					<div class="square"></div>
					附加信息
				</div>
				<el-row>
					<el-col :span="24">
						<el-form-item label="问题提醒额外收件箱" prop="othermails" :rules="rules.multiEmailRule">
							<el-input-tag v-model="othermails" :readOnly="disableEditSubmit || ApprovalDisable" placeholder="请输入正确邮箱格式。"></el-input-tag>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-form-item label="备注" prop="description">
							<el-input v-model="model.description" :disabled="disableEditSubmit || ApprovalDisable" type="textarea" :rows="4" maxlength="2000" :show-word-limit="true"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</div>
			<div class="form-content_trans"></div>
		</el-form>
		<tl-approval-history ref="history" sourceType="QemProblemAlert" :sourceId="model.id" />
		<div slot="footer" class="dialog-footer">
			<el-button :type="'primary'" id="bpa_button_style" @click="openRefFile">查看流程文档</el-button>
			<el-button :type="'primary'" v-if="!ApprovalOpen" @click="doCancelEdit">取消</el-button>
			<el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave"><svg-icon icon-class="save" />保存</el-button>
			<el-button type="primary" @click="submitApproval()" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval"><svg-icon icon-class="send" />提交审批</el-button>
			<upload-comp sourceType="QemProblemAlert" :sourceId="model.id" :disabled="disableAttachment" :editable="!disableEditSubmit" :limitSize="102400"></upload-comp>
			<el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory"><svg-icon icon-class="list" />审批历史</el-button>
		</div>
		<!-- <DutyDeptRef ref="qemDutyDeptRef" @confirm="getqemDutyDeptRefData" :isShowQryEnabled="false"></DutyDeptRef> -->
		<DutyDeptRef ref="qemDutyDeptRef" @confirm="getqemDutyDeptRefData" @clearRef="clearRef" :isShowQryEnabled="this.isShowQryEnabled" :isProductline="this.isProductline"></DutyDeptRef>
		<div v-show="showFileFlag" style="height:100vh;width:100vw;position:fixed;z-index:2520;top:0;left:0">
			<tl-iframe v-show="showFileFlag" ref="frame1" :url="localUrl" path="cdmc/fileInfoManage/fileSelectAndWatchComponent" :selectMode="'single'" :systemParamCode="'BPAQualityImprovementDirectory'" startMethod="open" :data="{ visible: true }" @close="cancel" height="100%"></tl-iframe>
		</div>
	</tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
import { mixin_form_validator } from '@/mixins/mixin_form_validator'
import { mixin_form_config } from '@/mixins/mixin_form_config'
/** 子组件 */
import DutyDeptRef from '@/views/qms/qemDutyDept/refList'
import RefDatacodeSelect from '@/utils/RefDatacodeSelect'
import uploadComp from '@/components/uploadComp'
/** 工具类 */
import { checkEmail } from '@/utils/email'
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
	mixins: [mixin_approval_edit, mixin_form_validator, mixin_form_config],
	components: { DutyDeptRef, RefDatacodeSelect, uploadComp },
	data() {
		return {
			moduleTitle: '问题告警单',
			urlPrefix: '/qms/qemProblemAlert/',
			url: {
				// 额外的url
				getUsersByCode: '/qms/qemDutyDept/getUsersByCode',
				queryDirectLeader: '/qms/qemProblemAlert/queryDirectLeader'
			},
			dutyRefProp: '',
			// 处理邮箱赋值
			othermails: [],
			// 表单必填 禁用状态设json
			formItemJson: {
				warningtitle: {
					maxlen: 30
				},
				problemdesc: {
					maxlen: 100
				},
				reviewman: {
					disabled: true,
					required: false
				},
				productlinename: {
					disabled: true,
					required: false
				},
				riskman: {
					disabled: true,
					required: false
				},
				assayer: {
					disabled: true,
					required: false
				},
				dutydeptname: {
					disabled: true,
					required: false
				}
			},
			isShowQryEnabled: false,
			isProductline: false,
			expireTimeOPtion: {
				disabledDate(time) {
					return time.getTime() > Date.now() - 8.64e6
				}
			},
			showFileFlag: false,
			localUrl: process.env.BPA_URL + '/dynamic'
		}
	},
	props: {
		render: {
			type: String,
			default: 'el-dialog'
		}
	},
	computed: {
		// 是否为审批打开页面
		ApprovalOpen() {
			return Object.keys(this.approvalNodeModel).length > 0
		},
		// 非复核界面
		ApprovalViewNode() {
			return this.formCode === 'review'
		},
		// 禁用字段
		ApprovalDisable() {
			return this.ApprovalOpen && !this.ApprovalViewNode
		},
		disabledFormItemWithPermission() {
			return function(prop) {
				return this.disabledFormItem(prop) || this.disableEditSubmit
			}
		}
	},
	watch: {
		othermails(newV, oldV) {
			if (newV.length > 0) {
				for (let i = 0; i < newV.length; i++) {
					var str = newV[i]
					var patt1 = /\b[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,6}\b/g
					var res = str.match(patt1)
					if (res === null) {
					} else {
					newV[i] = res[0]
				}
			}
			}
		let value = newV !== void 0 && newV.length > 0 ? newV.join(',') : ''
		this.$set(this.model, 'othermails', value)
		}
	},
	methods: {
		inputRequirements(val) {
			this.$set(this.model, 'requirements', val)
			this.$refs.form.validateField('requirements')
		},
		inputHappennode(val) {
			this.$set(this.model, 'happennode', val)
			this.$refs.form.validateField('happennode')
		},
		/** 关闭页面时，刷新主页面*/
		close() {
			this.$emit('refresh')
			// 清空邮箱赋值
			this.othermails = []
		},
		assignDefaultValue() {
			if (this.isAdd) {
				if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
					this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
				}
				this.queryDirectLeader()
				this.$set(this.model, 'orgcode', this.org.code)
				this.$set(this.model, 'orgname', this.org.name)
				this.$set(this.model, 'deptcode', this.dept.code)
				this.$set(this.model, 'deptname', this.dept.fullname)
				this.$set(this.model, 'usercode', this.user.code)
				this.$set(this.model, 'username', this.user.name)
				// 创建日期 默认当前日期
				this.$set(this.model, 'docdate', new Date())
				// 是否重复发生默认为否
				this.$set(this.model, 'repeat', 0)
				// 单据开立
				this.$set(this.model, 'state', 0)
				this.$set(this.model, 'warningtitle', '')
				this.$set(this.model, 'problemdesc', '')
				this.$set(this.model, 'rejects', '')
				this.$set(this.model, 'productname', '')
				this.$set(this.model, 'hardwareversion', '')
				this.$set(this.model, 'softwareversion', '')
				this.$set(this.model, 'mesbarcode', '')
				this.$set(this.model, 'sourcedocno', '')
				this.$set(this.model, 'classes', '')
				this.$set(this.model, 'sourcedesc', '')
				this.$set(this.model, 'emergenttreatment', '')
				this.$set(this.model, 'occurred', '')
				this.$nextTick(() => {
					this.$refs.form.clearValidate()
				})
			}
		},
		loaded() {
			// 页面加载完毕执行
			if (!this.isAdd && this.model.docno) {
				this.title = this.title + `（单据编号：${this.model.docno}）`
				// 邮箱展示处理
				if (this.model.othermails) {
					this.othermails = this.model.othermails.split(',')
				}
			}
		},
		/** 打开责任部门参照 */
		openqemDutyDeptRefDialog(prop) {
			this.dutyRefProp = prop
			if (this.dutyRefProp === 'productline') {
				this.isProductline = true
			} else {
				this.isProductline = false
			}
			this.$refs.qemDutyDeptRef.visible = true
		},
		/** 获取责任部门参数数据 */
		async getqemDutyDeptRefData(selectionRow, selectKey, selectionValue) {
			let code = selectionRow.code
			let name = selectionRow.name
			let username
			let usercode
			// 请求责任部门接口 获取所有配置人员
			let res = await getAction(this.url.getUsersByCode, { qry_code: '' + code })
			if (res.success) {
				username = res.result.usernames
				usercode = res.result.usercodes
			} else {
				// 请求失败暂取授权人员
				username = selectionRow.authorizernames
				usercode = selectionRow.authorizercodes
			}
			if (this.dutyRefProp === 'dutydept') {
				this.$set(this.model, 'dutydeptname', name)
				this.$set(this.model, 'dutydept', code)
				this.$set(this.model, 'dutyusercodes', usercode)
				this.$set(this.model, 'dutyusernames', username)
			} else if (this.dutyRefProp === 'productline') {
				this.$set(this.model, 'productlinename', name)
				this.$set(this.model, 'productline', code)
				this.$set(this.model, 'productlineusercodes', usercode)
				this.$set(this.model, 'productlineusernames', username)
			}
		},
		/** 提交审批前校验表单 */
		async submitApproval() {
			let valid = await this.$refs.form.validate()
			if (valid) {
				this.doSubmitApproval()
			}
		},
		async doSubmitEdit() {
			let valid = await this.$refs.form.validate()
			if (!this.beforeSubmit()) {
				return
			}
			if (valid) {
				// 复核人校验
				if (this.model.reviewmancode === this.$store.getters.user.code) {
					this.$tap.alert('复核人不能为自己！', 'warning')
					return false
				}
				// 保存时的邮箱校验
				if (this.model.othermails !== undefined && this.model.othermails !== null && this.model.othermails !== '' && !checkEmail(this.model.othermails, true, this.codeModel.emailWhiteList)) {
					this.$tap.alert('邮箱格式错误或邮箱不存在于白名单【' + this.codeModel.emailWhiteList + '】中', 'warning')
					return false
				}
				if (this.isAdd) {
					this.doAdd()
				} else {
					this.doEdit()
				}
			}
		},
		/* 审批前保存 并提示必填*/
		ApprovalEdit(resolve, reject) {
			this.saveLoading = true
			this.$refs.form.validate(valid => {
				if (!valid) {
					this.saveLoading = false
					reject()
				} else {
					if (this.model.othermails !== undefined && this.model.othermails !== null && this.model.othermails !== '' && !checkEmail(this.model.othermails, true, this.codeModel.emailWhiteList)) {
						this.$tap.alert('邮箱格式错误或邮箱不存在于白名单【' + this.codeModel.emailWhiteList + '】中', 'warning')
						reject()
						return
					}
					putAction(this.url.edit, this.model)
						.then(res => {
							if (res.success) {
								this.$tap.message(res.message, 'success')
								this.queryData(this.model.id)
								this.isAdd = false
								resolve()
							} else {
								this.$tap.alert(res.message, 'warning')
								reject()
							}
						})
						.catch(err => {
							reject()
						})
						.finally(() => {
							this.saveLoading = false
							this.afterSubmit()
						})
				}
			})
		},
		clearRef() {
			this.$refs.qemDutyDeptRef.visible = false
			if (this.dutyRefProp === 'dutydept') {
				this.$set(this.model, 'dutydeptname', '')
				this.$set(this.model, 'dutydept', '')
				this.$set(this.model, 'dutyusercodes', '')
				this.$set(this.model, 'dutyusernames', '')
			} else if (this.dutyRefProp === 'productline') {
				this.$set(this.model, 'productlinename', '')
				this.$set(this.model, 'productline', '')
				this.$set(this.model, 'productlineusercodes', '')
				this.$set(this.model, 'productlineusernames', '')
			}
		},
		// 打开流程文档参照
		openRefFile() {
			this.$refs.frame1.prefetchLoad()
			this.showFileFlag = true
		},
		// 关闭页面
		cancel() {
			this.$nextTick(() => {
				this.showFileFlag = false
			})
		},
		// 查询直属领导
		queryDirectLeader() {
			// 查询
			getAction(this.url.queryDirectLeader)
				.then(res => {
					if (res.success) {
						// 赋值
						this.$set(this.model, 'reviewmancode', res.result.leadercode)
						this.$set(this.model, 'reviewman', res.result.leadername)
					} else {
						// this.$tap.alert(res.message, 'warning')
					}
				})
				.catch(err => {})
		}
	}
	// mounted() {
	//     this.$refs.frame1.prefetch()
	// }
}
</script>
<style lang="scss" scoped>
.form-content {
	padding: 10px 15px;
	margin: 5px;
	background: white;
	border-radius: 5px;
	&_trans {
		background-color: rgba(0, 0, 0, 0);
		padding: 5px;
		margin: 5px;
	}
}
.tap-edit-dialog.tl-dialog {
	/deep/ .el-dialog__body {
		background-color: #eee;
		margin-bottom: 10px;
		padding: 5px 10px;
	}
}
#bpa_button_style {
	float: left;
}
</style>
